#include <stdlib.h>
#include <stdio.h>

void b16(int n)
{
	printf(" 0x");
	
	int i;
	char convert[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
	
	for (i=28;i>=0;i-=4)
	{
		printf("%c", convert[(( n >> i) & 15)]);
	}
}

void affiche(char* cor, int k, int first)
{
	b16(first);
	
	printf(" : ");
	
	for(int i=0;i<k;i++)
	{
		int f = cor[i]/16;
		if(f>9)
		{
			printf("%c", 'A'+f-10);
		}
		else
		{
			printf("%d", f);
		}
						
		f = cor[i]%16;
		if(f>9)
		{
			printf("%c", 'A'+f-10);
		}
		else
		{
			printf("%d", f);
		}
		
		printf(" ");
	
	}
	
	printf(" : ");
	
	for(int i=0;i<k;i++)
	{
		printf("%c", cor[i]);
	}
	
	
	printf("\n");
	
}

int main(int argc, char** argv)
{
	if(argc > 1)
	{
		int first = 0;
		if(argc > 2)
		{
			first = atoi(argv[2]);
		}
		
		FILE* file;
		file = fopen(argv[1], "r");
		
		if(file)
		{
			fseek(file, first, SEEK_SET);
			
			char cor[16];
			int k=0;
			
			while(! feof(file) )
			{
				//c = fgetc(file);
				cor[k] = fgetc(file);
				k++;
				first++;
				
				if(k==16)
				{
					affiche(cor, k, first - k);
					k=0;
				}
			}
			
			affiche(cor, k-1, first - k);
			
			fclose(file);
		}
	}
	
	
	return 0;
}
